//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "InterfaceConvect.h"

registerMooseObject("snakeApp", InterfaceConvect);

template <>
InputParameters
validParams<InterfaceConvect>()
{
  InputParameters params = validParams<InterfaceKernel>();
  params.addRequiredParam<Real>(
      "R", "The penalty that penalizes jump between master and neighbor variables.");
  return params;
}

InterfaceConvect::InterfaceConvect(const InputParameters & parameters)
  : InterfaceKernel(parameters), _R(1.0/getParam<Real>("R"))
{
}

Real
InterfaceConvect::computeQpResidual(Moose::DGResidualType type)
{
  Real r = 0;

  switch (type)
  {
    case Moose::Element:
      r = _test[_i][_qp] * _R * (_u[_qp] -_neighbor_value[_qp]);
      break;

    case Moose::Neighbor:
      r = _test_neighbor[_i][_qp] * -_R * (_u[_qp] -_neighbor_value[_qp]);
      break;
  }
  //if(_current_elem->id()==50&&_u[_qp]>0.01){
  // std::cout<<r<<" "<<_u[_qp]<<" "<<_neighbor_value[_qp]<<std::endl;
  //std::cout<<_current_elem->id()<<" "<<_neighbor_elem->id()<<" "<<_qp<<" "<<_R<<std::endl;
 // }
  
  //if(_current_elem->id()==50&&_u[_qp]>0.01)
  //getchar();
  return r;
}

Real
InterfaceConvect::computeQpJacobian(Moose::DGJacobianType type)
{
  Real jac = 0;

  switch (type)
  {
    case Moose::ElementElement:
      jac = _test[_i][_qp] * _R * _phi[_j][_qp];
      break;

    case Moose::ElementNeighbor:
      jac = _test[_i][_qp] * _R * -_phi_neighbor[_j][_qp];
      break;

    case Moose::NeighborElement:
      jac = _test_neighbor[_i][_qp] * -_R * _phi[_j][_qp];
      break;

    case Moose::NeighborNeighbor:
      jac = _test_neighbor[_i][_qp] * -_R * -_phi_neighbor[_j][_qp];
      break;
  }

  return jac;
}
